package com.inight.nightoj.judge.codesandbox;

import com.inight.nightoj.judge.codesandbox.model.ExecuteCodeRequest;
import com.inight.nightoj.judge.codesandbox.model.ExecuteCodeResponse;
import lombok.extern.slf4j.Slf4j;

/**
 * 代理, 以前是直接调用代码沙箱, 现在是通过这个代理去调用.
 * 实现接口: 是为了只做增强, 不做修改
 *
 * 代理模式
 */
@Slf4j
public class CodeSandboxProxy implements CodeSandbox{

    private CodeSandbox codeSandbox;

    public CodeSandboxProxy(CodeSandbox codeSandbox) {
        this.codeSandbox = codeSandbox;
    }


    @Override
    public ExecuteCodeResponse executeCode(ExecuteCodeRequest executeCodeRequest) {
        log.info("代码沙箱请求信息：" + executeCodeRequest.toString());
        ExecuteCodeResponse executeCodeResponse = codeSandbox.executeCode(executeCodeRequest);
        if(executeCodeResponse != null) {
            log.info("代码沙箱响应信息：" + executeCodeResponse.toString());
        }
        return executeCodeResponse;
    }
}
